package com.a1113;

import com.databases.dao.ClothesMapper;
import com.fullstack.bean.Clothes;
import com.fullstack.bean.Clothes_type;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.List;

public class a01 {

    //测试


    @Test
    //    对衣服进行条件查询
    public void select_dreamclothes(){
        List<Clothes> list = null;
        Clothes_type clothes_type= new Clothes_type();

        clothes_type.setId(90011);
        clothes_type.setBrand("Y-3");
        clothes_type.setType("男");
        clothes_type.setMoney_max(99999);
        clothes_type.setMoney_min(0);
        try {
            //执行Mybatis 存取数据库
            String resource = "SqlMapConfig.xml";           //绑定主体.xml

            //对SqlMapConfig.xml读取并解析
            InputStream inputStream = Resources.getResourceAsStream(resource);

            //获取会话工厂SqlSessionFactory
            SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

            //SqlSession主要用于对数据库的操作
            SqlSession session =  sessionFactory.openSession();     //获取数据库执行对象

            ClothesMapper mapper = session.getMapper(ClothesMapper.class);//接口名.class 获取对象   反射机制，通过接口，执行.xml里sql语句

            list = mapper.select_dreamclothes(clothes_type);

            session.commit();     //增删改需要执行事件 查询不用
            session.close();      //关闭
            inputStream.close();


        } catch (IOException e) {
            e.printStackTrace();
        }
        for(Clothes c : list){
            System.out.println(c.toString());
        }



           }

}

